import request from '@/router/axios'

export function fetchList (query) {
  return request({
    url: '/sys/user/page',
    method: 'get',
    params: query
  })
}

export function addObj (obj) {
  return request({
    url: '/sys/user',
    method: 'post',
    data: obj
  })
}

export function getObj (id) {
  return request({
    url: '/sys/user/' + id,
    method: 'get'
  })
}

export function delObj (id) {
  return request({
    url: '/sys/user/' + id,
    method: 'delete'
  })
}

export function putObj (obj) {
  return request({
    url: '/sys/user',
    method: 'put',
    data: obj
  })
}

export function getDetails (obj) {
  return request({
    url: '/sys/user/details/' + obj,
    method: 'get'
  })
}

export function fetchOrgAuthTree(id) {
  return request({
    url: '/sys/user/orgAuthTree',
    method: 'get',
    params: {
      userId: id
    }
  })

}

export function saveOrgAuth(id,data) {
  return request({
    url: '/sys/user/saveOrgAuth/'+id,
    method: 'post',
    data: data
  })

}

export const getUserInfo = () => {
  return request({
    url: '/sys/user/current',
    method: 'get'
  })
}
export function switchOrg(id) {
  return request({
    url: '/sys/user/switchOrg/'+id,
    method: 'post'
  })
}

export function resetPwd(id,newPassword) {
  return request({
    url: '/sys/user/resetPwd/'+id,
    method: 'post',
    data: {
      newPassword: newPassword
    }
  })

}

